package com.liudadan.spring_ioc_05;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;

import java.sql.PreparedStatement;

public class UserDao {
    public DruidDataSource dataSource;

    public void setDataSource(DruidDataSource dataSource) {
        this.dataSource = dataSource;
    }

    public void insert() throws Exception{
        DruidPooledConnection connection = dataSource.getConnection();

        String sql = "insert into sys_company (company_name) values (?);";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setObject(1,"邮政快递");
        int i = preparedStatement.executeUpdate();
        if(i>0){
            System.out.println("数据插入成功");
        }else {
            System.out.println("数据插入失败");
        }
        preparedStatement.close();
        connection.close();
    }
}
